package cn.yili12.business.repository;

import cn.yili12.business.entity.MessageDb;
import cn.yili12.business.entity.UserDb;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.Date;
import java.util.List;

@Repository
public interface UserRepository extends JpaRepository<UserDb, Long> {

    UserDb getByPhone(String phone);

    List<UserDb> findByOrgId(Long orgId);

    @Query("select new UserDb(user.id,user.name,user.sex,user.phone,user.password,user.remark,user.orgId,user.head,friend.updateTime)" +
            " from FriendDb friend left join UserDb user on user.id=friend.friendId where friend.userId=?1 order by friend.updateTime")
    List<UserDb> findFriendByUser(Long userId);
}
